package com.tianyang.yukuaifu.business.auth.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.tianyang.yukuaifu.business.auth.bean.CompanyBasicInput;
import com.tianyang.yukuaifu.business.auth.bean.CompanyLegalInput;
import com.tianyang.yukuaifu.business.auth.bean.CompanySettleInput;
import com.tianyang.yukuaifu.business.auth.bean.CompanyStoreInput;
import com.tianyang.yukuaifu.business.auth.bean.IndividualSettleInput;
import com.tianyang.yukuaifu.business.auth.bean.MerchantBasicInput;
import com.tianyang.yukuaifu.business.auth.bean.MerchantLegalInput;

import java.util.HashMap;
import java.util.Map;

/**
 * Description：实名数据转换
 * Created by xyj on 2024/3/14
 */
public class AuthConverter {

    private static volatile AuthConverter mInstance;

    private AuthConverter() {
        if (mInstance != null) {
            throw new IllegalStateException("Already initialized.");
        }
    }

    public static AuthConverter getInstance() {
        AuthConverter result = mInstance;
        if (result == null) {
            synchronized (AuthConverter.class) {
                result = mInstance;
                if (result == null) {
                    mInstance = result = new AuthConverter();
                }
            }
        }
        return result;
    }

    public Map<String, String> getAuthMerchantInput(MerchantBasicInput basicInput, MerchantLegalInput legalInput) {
        Map<String, String> basicMap = new HashMap<>();
        if (basicInput != null) {
            basicMap = JSON.parseObject(JSONObject.toJSONString(basicInput), new TypeReference<Map<String, String>>(){});
        }
        Map<String, String> legalMap = new HashMap<>();
        if (legalInput != null) {
            legalMap = JSON.parseObject(JSONObject.toJSONString(legalInput), new TypeReference<Map<String, String>>(){});
        }
        basicMap.putAll(legalMap);
        return basicMap;
    }

    public Map<String, String> getAuthIndividualInput(CompanyBasicInput basicInput, CompanyLegalInput legalInput,
                                                          IndividualSettleInput settleInput, CompanyStoreInput storeInput) {
        Map<String, String> basicMap = new HashMap<>();
        if (basicInput != null) {
            basicMap = JSON.parseObject(JSONObject.toJSONString(basicInput), new TypeReference<Map<String, String>>(){});
        }
        Map<String, String> legalMap = new HashMap<>();
        if (legalInput != null) {
            legalMap = JSON.parseObject(JSONObject.toJSONString(legalInput), new TypeReference<Map<String, String>>(){});
        }
        basicMap.putAll(legalMap);
        Map<String, String> settleMap = new HashMap<>();
        if (settleInput != null) {
            settleMap = JSON.parseObject(JSONObject.toJSONString(settleInput), new TypeReference<Map<String, String>>(){});
        }
        basicMap.putAll(settleMap);
        Map<String, String> storeMap = new HashMap<>();
        if (storeInput != null) {
            storeMap = JSON.parseObject(JSONObject.toJSONString(storeInput), new TypeReference<Map<String, String>>(){});
        }
        basicMap.putAll(storeMap);
        return basicMap;
    }

    public Map<String, String> getAuthCompanyInput(CompanyBasicInput basicInput, CompanyLegalInput legalInput,
                                                   CompanySettleInput settleInput, CompanyStoreInput storeInput) {
        Map<String, String> basicMap = new HashMap<>();
        if (basicInput != null) {
            basicMap = JSON.parseObject(JSONObject.toJSONString(basicInput), new TypeReference<Map<String, String>>(){});
        }
        Map<String, String> legalMap = new HashMap<>();
        if (legalInput != null) {
            legalMap = JSON.parseObject(JSONObject.toJSONString(legalInput), new TypeReference<Map<String, String>>(){});
        }
        basicMap.putAll(legalMap);
        Map<String, String> settleMap = new HashMap<>();
        if (settleInput != null) {
            settleMap = JSON.parseObject(JSONObject.toJSONString(settleInput), new TypeReference<Map<String, String>>(){});
        }
        basicMap.putAll(settleMap);
        Map<String, String> storeMap = new HashMap<>();
        if (storeInput != null) {
            storeMap = JSON.parseObject(JSONObject.toJSONString(storeInput), new TypeReference<Map<String, String>>(){});
        }
        basicMap.putAll(storeMap);
        return basicMap;
    }
}
